class AceHUD extends HUD;

// The texture which represents the cursor on the screen
var const Texture2D CursorTexture; 
// The color of the cursor
var const Color CursorColor;

var bool bDrawMouseCursor;
var Vector MouseWorldLocation;
var Actor MouseTraceHit;
var TraceHitInfo MouseTraceHitInfo;

event PostRender()
{
	local AcePlayerInput PInput;

	if (PlayerOwner != None && CursorTexture != None) 
	{
		PInput = AcePlayerInput(PlayerOwner.PlayerInput); 

		if (PInput != None)
		{
			if(bDrawMouseCursor)
			{
				Canvas.SetPos(PInput.MousePosition.X, PInput.MousePosition.Y); 
				Canvas.DrawColor = CursorColor;
				Canvas.DrawTile(CursorTexture, CursorTexture.SizeX, CursorTexture.SizeY, 0.f, 0.f, CursorTexture.SizeX, CursorTexture.SizeY,, true);
			}
		}
	}

	MouseWorldLocation = GetMouseWorldLocation();
	
	PlayerOwner.DrawHUD(self);
}

function Vector GetMouseWorldLocation()
{
	local AcePlayerInput PInput;
	local Vector2D MousePosition;
	local Vector MouseWorldOrigin, MouseWorldDirection, HitLocation, HitNormal;

	// Ensure that we have a valid canvas and player owner
	if (Canvas == None || PlayerOwner == None)
	{
		return Vect(0, 0, 0);
	}

	// Type cast to get the new player input
	PInput = AcePlayerInput(PlayerOwner.PlayerInput);

	// Ensure that the player input is valid
	if (PInput == None)
	{
		return Vect(0, 0, 0);
	}

	// We stored the mouse position as an IntPoint, but it's needed as a Vector2D
	MousePosition.X = PInput.MousePosition.X;
	MousePosition.Y = PInput.MousePosition.Y;
	// Deproject the mouse position and store it in the cached vectors
	Canvas.DeProject(MousePosition, MouseWorldOrigin, MouseWorldDirection);

	// Perform a trace to get the actual mouse world location.
	MouseTraceHit = Trace(HitLocation, HitNormal, MouseWorldOrigin + MouseWorldDirection * 65536.f, MouseWorldOrigin , true,, MouseTraceHitInfo, TRACEFLAG_Bullet);
	return HitLocation;
}

defaultproperties
{
	CursorColor=(R=255,G=255,B=255,A=255)
	CursorTexture=Texture2D'EngineResources.Cursors.Arrow'

	bDrawMouseCursor = false
}